﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using WhereIam.Dbs;
using WhereIam.Entities;

namespace WhereIam.Moduels
{
    public partial class DailyLocation : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var bll = new DailyLocationBll();

                var list = bll.GetByCondition("*",
                    string.Format(" AND date_format(Today,'%Y-%m-%d')='{0}'", DateTime.Now.ToString("yyyy-MM-dd")));
                
                    var bllE = new EmployeesOfLocationBll();

                    var listE = bllE.GetAll();
                    var listDL = new List<Entities.DailyLocation>();
                    if (listE.Any() && listE.Count!=list.Count)
                    {
                        foreach (var obj in listE)
                        {
                            if(list.Any(o=>o.EmployeeName==obj.FullName))
                            { 
                           
                            }
                            else
                            {
                                var dl = new Entities.DailyLocation();
                                dl.IdDailyLocation = Commons.GenerateIdByForeTag("DL");
                                dl.DeptName = obj.DeptName;
                                dl.EmployeeName = obj.FullName;
                                dl.Today = DateTime.Now;
                                listDL.Add(dl);
                            }
                        }

                        bll.InsertMulty(listDL);
                        Response.Redirect(Request.Url.ToString());
                    }
            }
        }
    }
}